from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import Integer, String
from ..database.db import Base

class Users(Base):
    __tablename__ = 'users'

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    username: Mapped[str] = mapped_column(String(50))
    password: Mapped[str] = mapped_column(String(50))
    gender: Mapped[str | None] = mapped_column(String(50))
    permissions: Mapped[int | None] = mapped_column(Integer, default=1)

    # 使用字符串形式指定 Folder 类
    folders = relationship("Folder", back_populates="user")

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
